package queueenum

import (
	"yunj/pkg/yunj/core/enum"
)

// 此处不自定义类型，防止数据库占位符?替换为字符串，在mysql进行匹配时发生类型转换

// 定义常量
const (
	// 处理中
	HANDLE_STATUS_PROGRESS = iota

	// 处理完成
	HANDLE_STATUS_COMPLETED

	// 处理失败
	HANDLE_STATUS_FAILED
)

// 实现EnumInerface接口
type HandleStatus struct {
	enum.Enum[int]
}

// HandleStatus.GetInstance().GetDescMap()
func (e *HandleStatus) AllConstAttrs() map[int]map[string]any {
	return map[int]map[string]any{
		HANDLE_STATUS_PROGRESS: {
			"desc":  "处理中",
			"sort":  1,
			"color": "#2F363C",
		},
		HANDLE_STATUS_COMPLETED: {
			"desc":  "完成",
			"sort":  2,
			"color": "#009688",
		},
		HANDLE_STATUS_FAILED: {
			"desc":  "失败",
			"sort":  3,
			"color": "#FF5722",
		},
	}
}

// 存储已经创建的实例
var handleStatusInstanceCache = make(map[int]*HandleStatus)

// 根据value获取枚举
func HandleStatusByValue(value int) *HandleStatus {
	if instance, exists := handleStatusInstanceCache[value]; exists {
		return instance
	}
	e := &HandleStatus{}
	enum.SetEnumInstance(&e.Enum, e, value)
	handleStatusInstanceCache[value] = e
	return e
}

var HandleStatusEnum *HandleStatus = func() *HandleStatus {
	e := &HandleStatus{}
	enum.SetEnumInstance(&e.Enum, e)
	return e
}()
